/*
 * @Author: liu.lin liu.lin@hzleaper.com
 * @Date: 2023-11-08 11:05:26
 * @LastEditors: liu.lin liu.lin@hzleaper.com
 * @LastEditTime: 2023-11-10 14:10:30
 * @FilePath: \aoi_link_frontend\src\App.tsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { ConfigProvider } from 'antd';
import { observer } from 'mobx-react-lite';
import React, { useEffect, useState } from 'react';
// import { BrowserRouter, } from 'react-router-dom';
import locale from 'antd/es/locale/zh_CN';
import 'moment/dist/locale/zh-cn';
import moment from 'moment';
import routes from './router';
import { getGlobalConfig } from './api/config';
import { useStores } from '@/stores';
import { Storage } from '@/utils/storage';
import { BrowserRouter, HashRouter, Outlet, useRoutes } from 'react-router-dom';
moment.locale('zh-cn', {
  week: {
    dow: 1
  }
});

const Routes = () => useRoutes(routes);

const App: React.FC = () => {
  const { commonStore, markingStore, lotStore, sysMapStore } = useStores();
  const [show, setShow] = useState<boolean>(false);
  useEffect(() => {
    getRequestConfig();
  }, []);

  /**
   * link前端初始化请求
   * 给各个store赋值
   */
  const getRequestConfig = async () => {
    try {
      console.log('App---进入App请求config配置里的信息！');
      const resBack = await getGlobalConfig();
      console.log(`getGlobalConfig`, resBack);

      commonStore.setDefaultSetting(resBack.data.flawTypeConf, sysMapStore, lotStore); // 缺陷全集给详情页赋值
      setShow(true);
      markingStore.setDefaultAllNotGoodType(resBack.data.markingTypeConf); // 不良全集给marking页面赋值
      lotStore.setCardFlawAlias(resBack.data.flawAlias); // 给详情页缺陷别名进行赋值
      Storage.set('layerIdFlawType', resBack.data.flawTypeConf); // 整个页面的缺陷全集
      Storage.set('allMarkingAllNotGoodType', resBack.data.markingTypeConf); // 整个页面的不良缺陷的全集
    } catch (error) {
      console.log(error);
    }
  };

  return (
    <>
      {show ? (
        <>
          {' '}
          <ConfigProvider componentSize="middle" locale={locale}>
            <BrowserRouter>
              <Routes></Routes>
            </BrowserRouter>
            {/* <HashRouter>
        <Route></Route>
       </HashRouter> */}
          </ConfigProvider>
        </>
      ) : (
        ''
      )}
    </>
  );
};

export default observer(App);
